/*移动端返回事件处理*/
function judgeOnBack() {
    return 1; //1回到工作台
}
$(function () {
    //var partCode='1259W';
    //var partCode='90011058M';
    var partCode='020211317M';
    var type=1;  //零件类型 1模具 2 注塑 3金属
    /*试模列表*/
    var testModeList='';        //临时存放所有试模列表数据
    var testModeListlen=[];     //临时存放未完成试模数量

    //扫码进入试模
    function testList() {
        var url='/test/mode/list';
        var mdObj=md5Fun(appUserId,url,appToken);
        var parameterObj= {
            "partCode":partCode,
            "type":type
        };
        var parameter=Encrypt(JSON.stringify(parameterObj));
        console.log(parameter)
        console.log(Decrypt(parameter));
        $.ajax({
            type: "POST",
            timeout : 5000,
            url: webUrlCon+url,
            data:JSON.stringify(
                {"parameter":parameter}
            ),
            beforeSend: function(request) {
                request.setRequestHeader("Content-Type", "application/json");
                request.setRequestHeader("sequence", mdObj.sequence);
                request.setRequestHeader("nonceStr", mdObj.nonceStr);
                request.setRequestHeader("userId", appUserId);
                request.setRequestHeader("token",appToken);
                //xmlhttp.setRequestHeader("infName", url);
                //xmlhttp.setRequestHeader("osVersion", '');
                request.setRequestHeader("versionType", "1");
                request.setRequestHeader("osPlatform", mdObj.osPlatform);
                request.setRequestHeader("appVersion", mdObj.appVersion);
                request.setRequestHeader("sign", mdObj.sign);
            },
            success: function (data) {
                //console.log(data);
                if(data.code==100){
                    testModeList=Decrypt(data.content);
                    console.log(JSON.parse(testModeList));
                    testListHtml(0);
                }else if(data.code==102){
                    //没有找到该零件监控编号的信息
                    layer.open({
                        content: data.message
                        ,btn: '确定'
                    });
                }else{
                    layer.open({
                        content: data.code+' '+data.message
                        ,btn: '确定'
                    });
                }
            },
            error: function(e) {
                layer.open({
                    content: '无法请求服务器，请稍后再试！'
                    ,btn: '确定'
                });
            }
        });
    }
    //testList()

    if (u.indexOf('iPhone') > -1) {   //苹果手机
        setTimeout(function () {
            WebViewJavascriptBridge.callHandler('setRight', {'text': '历史试模','url':'testHistory.html'}, function(response) {

            })
            WebViewJavascriptBridge.callHandler('getPartCode', {'foo': 'bar'}, function(response) {
                response=JSON.parse(response);
                testModeList=response.partCode;
                appToken=response.token;
                appUserId=response.userId;
                localStorage.appToken=appToken;
                localStorage.appUserId=appUserId;
                testListHtml(0);
                dept();
            })
        },50);
    }else {
        var response=jsObj.getPartCode();
        //alert(response)
        response=JSON.parse(response);
        testModeList=response.partCode;
        //alert(testModeList)
        appToken=response.token;
        appUserId=response.userId;
        localStorage.appToken=appToken;
        localStorage.appUserId=appUserId;
        jsObj.setRight('历史试模','testHistory.html');
        testListHtml(0);
        dept();
    }

    /* OSS*/
    //send_request();

    /*生成已完成试模*/
    function testListHtml(leng) {
        $('.spinner').show();
        var testModeListObj=JSON.parse(testModeList);
        partCode=testModeListObj[leng].partCode;
        if(testModeListObj.length>0){ //是否有试模数据
            //获取未完成试模
            for(var i=0;i<testModeListObj.length;i++){
                if(testModeListObj[i].status==0||testModeListObj[i].status==1){
                    testModeListlen.push(i);
                }
            }
            if(testModeListlen.length>0){  //是否有未完成的试模
                //试模基础信息
                $('.modeInfo .title').html('试模产品编号：'+testModeListObj[testModeListlen[leng]].assemblCode);
                var conHtml='<p><span>产品名称：</span>'+testModeListObj[testModeListlen[leng]].productName+'</p>' +
                    '<p><span>产品编号：</span>'+testModeListObj[testModeListlen[leng]].productCode+'</p>' +
                    '<p><span>生产单号：</span>'+testModeListObj[testModeListlen[leng]].productOrderCode+'</p>' +
                    '<p><span>零件总数：</span>'+testModeListObj[testModeListlen[leng]].partCount+'</p>';
                $('.modeInfo .content').html(conHtml);
                //
                $('.modeInfo').attr('data-id',testModeListObj[testModeListlen[leng]].id);
                $('.modeInfo').attr('product-order-id',testModeListObj[testModeListlen[leng]].productOrderId);
                $('.modeInfo').attr('assembl-code',testModeListObj[testModeListlen[leng]].assemblCode);
                //生成菜单
                if(testModeListlen.length>1){  //是否有多个试模
                    var navHtml='';
                    for(var i=0;i<testModeListlen.length;i++){
                        if(i==0){
                            navHtml+='<li class="active" data-id=0><span>试模1</span></li>'
                        }else{
                            navHtml+='<li data-id='+parseInt(i+1)+'><span>试模'+parseInt(parseInt(i+1))+'</span></li>'
                        }
                    }
                    if(testModeListlen.length==2){$('.TabNavUl').addClass('ul2')}
                    if(testModeListlen.length==3){$('.TabNavUl').addClass('ul3')}
                    if(testModeListlen.length==4){$('.TabNavUl').addClass('ul4')}
                    $('.TabNavUl').html(navHtml);
                    tabNavRefresh()
                }else {
                    //隐藏菜单
                    $('.TabNavUl').hide();
                    $('.TabMain').css('padding','0 0 1.1733333rem 0');
                }
                //是否有试模详情信息
                $('.testT').remove();  //初始化
                //是否有试模详细信息
                if(testModeListObj[testModeListlen[leng]].status==1){
                    var testHtml='';
                    var listTestModeDetail=testModeListObj[testModeListlen[leng]].listTestModeDetail;
                    var j=0;
                    for(var i=0;i<listTestModeDetail.length;i++){
                        if(listTestModeDetail[i].status==2){ //已完成
                            testHtml+='<li class="testT">' +
                                '<div class="title">T'+j+'试模（完成）：'+listTestModeDetail[i].factHours+'h '+formatDateTime(listTestModeDetail[i].startDate)+'开始</div>' +
                                '<div class="isShow">展开</div>' +
                                '<div class="contentBox" style="display: none;">';

                            if(listTestModeDetail[i].deptName!=undefined){
                                testHtml+='<div class="content"><p>问题负责组别：'+listTestModeDetail[i].deptName+'、'+listTestModeDetail[i].groupName+'</p></div>';
                            }else{
                                testHtml+='<div class="content"><p>问题负责组别：无</p></div>';
                            }
                            if(listTestModeDetail[i].modeImg!=''){
                                testHtml+='<div class="content">' +
                                    '<p>试模图片</p>' +
                                    '<div class="testImages">';
                                var modeImg=listTestModeDetail[i].modeImg.split(',');
                                for(var k=0;k<modeImg.length;k++){
                                    testHtml+='<div class="img"><img onclick="zoomAlert(this)" src="'+ossUrl+modeImg[k]+'" /></div>';
                                }
                                testHtml+='</div>' +
                                    '</div>';
                            }
                            if(listTestModeDetail[i].content!=''){
                                testHtml+='<div class="content">' +
                                    '<p>试模报告</p>' +
                                    '<p class="testReport">'+listTestModeDetail[i].content+'</p>' +
                                    '</div>';
                            }
                            testHtml+='</div>' +
                                '</li>';
                            j++;
                        }
                    }
                    $('.modeInfo').after(testHtml);
                    //初始化进行试模框
                    $('.testInfo').find('.title').html('<span class="testStartTxt">T'+$('.testT').length+'试模（未开始）</span>');
                    $('.testInfo').find('.contentBox').hide();
                    $('.testInfo').find('.testStart').html('开始T'+$('.testT').length+'试模');
                    $('.testInfo').find('.testStart').show();
                    for(var i=0;i<listTestModeDetail.length;i++){
                        if(listTestModeDetail[i].status==1){ //进行中
                            //
                            $('.testInfo').attr('start-date',formatDateTime(listTestModeDetail[i].startDate));
                            $('.testInfo').attr('test-mode-detailid',listTestModeDetail[i].testModeDetailid);
                            //
                            $('.testInfo').find('.contentBox').find('div.img').remove();
                            $('#group').html('');
                            //addressLocation.locatePostion(0,0);
                            $('.testReportArea textarea').val(listTestModeDetail[i].content==undefined?'':listTestModeDetail[i].content);
                            $('.group').css('color','initial');
                            $('.testInfo').find('.title').html('T'+j+'试模（进行中）：开始时间'+formatDateTime(listTestModeDetail[i].startDate));
                            $('.testInfo').find('.contentBox').show();
                            $('.testInfo').find('.testStart').hide();
                        }
                    }
                    if($('.testT').length>1){
                        $('.testDel').show();
                        $('.testStorage').show();
                    }else{
                        $('.testDel').hide();
                        $('.testStorage').hide();
                    }
                }
                $('.main').show();
                $('.spinner').hide();
            }else{
                layer.open({
                    content: '该零件监控编号已完试模，跳转到历史试模页面'
                    ,btn: '确定'
                    ,shadeClose:false
                    , yes: function(index){
                        layer.close(index)
                        if (u.indexOf('iPhone') > -1) {   //苹果手机
                            location.href='testHistory.html';
                        }else {
                            jsObj.openHyperLinkReference('testHistory.html');
                        }
                    }
                });
            }
        }else{
            $('.main').hide();
            $('.spinner').hide();
            layer.open({
                content: '没有找到该零件监控编号的信息'
                ,btn: '确定'
            });
        }
    }


    //问题负责组别
    var addressLocation='';
    var deptArr='';  //存放所有部门列表
    /*部门列表*/
    function dept() {
        var url='/test/mode/list/dept';
        var mdObj=md5Fun(appUserId,url,appToken);
        $.ajax({
            type: "POST",
            timeout : 5000,
            url: webUrlCon+url,
            beforeSend: function(request) {
                request.setRequestHeader("Content-Type", "application/json");
                request.setRequestHeader("sequence", mdObj.sequence);
                request.setRequestHeader("nonceStr", mdObj.nonceStr);
                request.setRequestHeader("userId", appUserId);
                request.setRequestHeader("token",appToken);
                //xmlhttp.setRequestHeader("infName", url);
                //xmlhttp.setRequestHeader("osVersion", '');
                request.setRequestHeader("versionType", "1");
                request.setRequestHeader("osPlatform", mdObj.osPlatform);
                request.setRequestHeader("appVersion", mdObj.appVersion);
                request.setRequestHeader("sign", mdObj.sign);
            },
            success: function (data) {
                //console.log('/test/mode/list/dept');
                //console.log(data);
                if(data.code==100) {
                    deptArr=Decrypt(data.content);
                    deptArr=JSON.parse(deptArr);
                    var deptArrNew=[{'id':-1,'value':'无'}];
                    deptArr=deptArrNew.concat(deptArr);
                    //console.log(deptArr);
                    var groupArr=[{'id':-1,'value':''}];
                    var url='/test/mode/list/group';
                    var mdObj=md5Fun(appUserId,url,appToken);
                    var parameterObj= {
                        "deptId":deptArr[0].id
                    };
                    var parameter=Encrypt(JSON.stringify(parameterObj));
                    //console.log(parameter)
                    //console.log(Decrypt(parameter));
                    $.ajax({
                        type: "POST",
                        timeout : 5000,
                        url: webUrlCon+url,
                        data:JSON.stringify(
                            {"parameter":parameter}
                        ),
                        beforeSend: function(request) {
                            request.setRequestHeader("Content-Type", "application/json");
                            request.setRequestHeader("sequence", mdObj.sequence);
                            request.setRequestHeader("nonceStr", mdObj.nonceStr);
                            request.setRequestHeader("userId", appUserId);
                            request.setRequestHeader("token",appToken);
                            //xmlhttp.setRequestHeader("infName", url);
                            //xmlhttp.setRequestHeader("osVersion", '');
                            request.setRequestHeader("versionType", "1");
                            request.setRequestHeader("osPlatform", mdObj.osPlatform);
                            request.setRequestHeader("appVersion", mdObj.appVersion);
                            request.setRequestHeader("sign", mdObj.sign);
                        },
                        success: function (data) {
                            //console.log('/test/mode/list/group');
                            //console.log(data);
                            if(data.code==100) {
                                var groupArrObj=Decrypt(data.content);
                                //alert(groupArrObj)
                                groupArrObj=JSON.parse(groupArrObj);
                                //console.log(groupArrObj);
                                if(groupArrObj.length>0){
                                    groupArr=groupArrObj
                                }
                                addressLocation= new MobileSelect({
                                    trigger: '#group',
                                    title: '问题负责组别',
                                    wheels: [
                                        {data:deptArr},
                                        {data:groupArr}
                                    ],
                                    triggerDisplayData:false,
                                    position:[0,0],
                                    callback:function(indexArr, data){
                                        $('.group').css('color','initial');
                                        //console.log(data); //返回选中的json数据
                                        $('#group').attr('dept-id',data[0].id);
                                        $('#group').attr('group-id',data[1].id);
                                    },
                                    transitionEnd:function(indexArr, data){
                                        //console.log(indexArr); //
                                        //console.log(data); //返回选中的json数据
                                        group(data[0].id);
                                    }
                                });
                            }
                        }
                    });
                }
            },
            error: function(e) {

            }
        });
    }
    /*部门组别列表*/
    var groupId='';  //是否请求部门组别数据
    function group(deptId) {
        var url='/test/mode/list/group';
        var mdObj=md5Fun(appUserId,url,appToken);
        var parameterObj= {
            "deptId":deptId
        };
        var parameter=Encrypt(JSON.stringify(parameterObj));
        if(groupId!=deptId&&deptId!=''){
            $.ajax({
                type: "POST",
                timeout : 5000,
                url: webUrlCon+url,
                data:JSON.stringify(
                    {"parameter":parameter}
                ),
                beforeSend: function(request) {
                    request.setRequestHeader("Content-Type", "application/json");
                    request.setRequestHeader("sequence", mdObj.sequence);
                    request.setRequestHeader("nonceStr", mdObj.nonceStr);
                    request.setRequestHeader("userId", appUserId);
                    request.setRequestHeader("token",appToken);
                    //xmlhttp.setRequestHeader("infName", url);
                    //xmlhttp.setRequestHeader("osVersion", '');
                    request.setRequestHeader("versionType", "1");
                    request.setRequestHeader("osPlatform", mdObj.osPlatform);
                    request.setRequestHeader("appVersion", mdObj.appVersion);
                    request.setRequestHeader("sign", mdObj.sign);
                },
                success: function (data) {
                    layer.closeAll();
                    //console.log('/test/mode/list/groupArrgroupArrgroupArrgroupArr');
                    //console.log(data);
                    if(data.code==100) {
                        var groupArr=Decrypt(data.content);
                        groupArr=JSON.parse(groupArr);
                        //console.log(groupArr);
                        if(groupArr.length==0){
                            groupArr.push({'id':-1,'value':''})
                        }
                        addressLocation.updateWheel(1,groupArr);
                        addressLocation.locatePostion(1,0);
                    }
                },
            });
        }
        groupId=deptId;
    }
    //收起，展开
    $('.main').on('click','.isShow',function () {
        if($(this).html()=='收起'){
            $(this).siblings('.contentBox').hide();
            $(this).html('展开');
        }else{
            $(this).siblings('.contentBox').show();
            $(this).html('收起');
        }
    });
    //开始试模
    $('.main').on('click','.testStart',function () {
        layer.open({type: 2,shadeClose: false,});
        var url='/test/mode/handle';
        var mdObj=md5Fun(appUserId,url,appToken);
        var parameterObj= {
            "productOrderId":$('.modeInfo').attr('product-order-id'),
            "type":1,
            "partCode":partCode,
            "tCount":parseInt($('.testT').length),
            "assemblCode":$('.modeInfo').attr('assembl-code'),
        };
        var parameter=Encrypt(JSON.stringify(parameterObj));
        //console.log(parameter)
        console.log(Decrypt(parameter));
        $.ajax({
            type: "POST",
            timeout : 5000,
            url: webUrlCon+url,
            data:JSON.stringify(
                {"parameter":parameter}
            ),
            beforeSend: function(request) {
                request.setRequestHeader("Content-Type", "application/json");
                request.setRequestHeader("sequence", mdObj.sequence);
                request.setRequestHeader("nonceStr", mdObj.nonceStr);
                request.setRequestHeader("userId", appUserId);
                request.setRequestHeader("token",appToken);
                //xmlhttp.setRequestHeader("infName", url);
                //xmlhttp.setRequestHeader("osVersion", '');
                request.setRequestHeader("versionType", "1");
                request.setRequestHeader("osPlatform", mdObj.osPlatform);
                request.setRequestHeader("appVersion", mdObj.appVersion);
                request.setRequestHeader("sign", mdObj.sign);
            },
            success: function (data) {
                layer.closeAll();
                //console.log(data);
                if(data.code==100) {
                    var content=Decrypt(data.content);
                    content=JSON.parse(content);
                    console.log(content);
                    //
                    $('.modeInfo').attr('data-id',content.id);
                    $('.testInfo').attr('test-mode-detailid',content.testModeDetailid);
                    $('.testInfo').attr('start-date',formatDateTime(content.startDate));
                    //初始化试模框
                    $('.testInfo').find('.contentBox').find('div.img').remove();
                    $('#group').html('');
                    //addressLocation.locatePostion(0,0);
                    $('.testReportArea textarea').val('');
                    $('.group').css('color','initial');
                    $('.testInfo').find('.title').html('T'+$('.testT').length+'试模（进行中）：开始时间'+formatDateTime(content.startDate));
                    $('.testInfo').find('.contentBox').show();
                    $('.testInfo').find('.testStart').hide();
                    if($('.testT').length>1){
                        $('.testDel').show();
                        $('.testStorage').show();
                    }else{
                        $('.testDel').hide();
                        $('.testStorage').hide();
                    }
                }else {
                    layer.open({
                        content: data.code+' '+data.message
                        ,btn: '确定'
                    });
                }
            },
            error: function(e) {
                layer.closeAll();
                layer.open({
                    content: '无法请求服务器，请稍后再试！'
                    ,btn: '确定'
                });
            }
        });


    });
    //完成试模
    $('.main').on('click','.testEnd',function () {
        var _this=this;
        var con='T'+$('.testT').length+'已完成试模';
        if($('.testT').length==1){
            con='T'+$('.testT').length+'已完成试模，模具可入库或继续进行试模';
        }
        layer.open({
            content: con
            ,btn: ['确定', '取消']
            ,yes: function(index){
                layer.close(index);
                if($('#group').html()!=''){
                    layer.open({type: 2,shadeClose: false,});
                    var imgSrcUrl=new Array();
                    $("#testImages .img").each(function(index){
                        imgSrcUrl[index]=$(this).find('img').attr('data-url');
                    });
                    imgSrcUrl=imgSrcUrl.join(',');
                    var url='/test/mode/handle';
                    var mdObj=md5Fun(appUserId,url,appToken);
                    var fzDept=parseInt($('#group').attr('dept-id'))==-1?'':parseInt($('#group').attr('dept-id'));
                    var fzGroup=parseInt($('#group').attr('group-id'))==-1?'':parseInt($('#group').attr('group-id'));
                    var parameterObj= {
                        "id":$('.modeInfo').attr('data-id'),
                        "type":2,
                        "partCode":partCode,
                        "img":imgSrcUrl,
                        "content":$('#testReportArea').val(),
                        "fzDept":fzDept,
                        "fzGroup":fzGroup,
                        "testModeDetailid":$('.testInfo').attr('test-mode-detailid')
                    };
                    var parameter=Encrypt(JSON.stringify(parameterObj));
                    console.log('完成试模======================================')
                    console.log(parameter)
                    console.log(Decrypt(parameter));
                    $.ajax({
                        type: "POST",
                        timeout : 5000,
                        url: webUrlCon+url,
                        data:JSON.stringify(
                            {"parameter":parameter}
                        ),
                        beforeSend: function(request) {
                            request.setRequestHeader("Content-Type", "application/json");
                            request.setRequestHeader("sequence", mdObj.sequence);
                            request.setRequestHeader("nonceStr", mdObj.nonceStr);
                            request.setRequestHeader("userId", appUserId);
                            request.setRequestHeader("token",appToken);
                            //xmlhttp.setRequestHeader("infName", url);
                            //xmlhttp.setRequestHeader("osVersion", '');
                            request.setRequestHeader("versionType", "1");
                            request.setRequestHeader("osPlatform", mdObj.osPlatform);
                            request.setRequestHeader("appVersion", mdObj.appVersion);
                            request.setRequestHeader("sign", mdObj.sign);
                        },
                        success: function (data) {
                            layer.closeAll();
                            console.log(data);
                            if(data.code==100) {
                                var content=Decrypt(data.content);
                                content=JSON.parse(content);
                                console.log(content);
                                console.log('完成试模======================================END')

                                var str='<li class="testT">' +
                                '<div class="title">T'+$('.testT').length+'试模（完成）：'+content.hours+'h  '+$('.testInfo').attr('start-date')+'开始</div>' +
                                '<div class="isShow">展开</div>' +
                                '<div class="contentBox" style="display:none;">' +
                                '<div class="content">' +
                                '<p>问题负责组别：'+$('#group').html()+'</p>' +
                                '</div>';
                                if($('#testImages .img').length>0){
                                    str+='<div class="content">' +
                                        '<p>试模图片</p>' +
                                        '<div class="testImages">';
                                    $('#testImages .img').each(function () {
                                        str+='<div class="img">' +
                                            '<img onclick="zoomAlert(this)" src="'+$(this).find('img').attr('src')+'">' +
                                            '</div>';
                                    })
                                    str+='</div>' +
                                        '</div>';
                                }
                                if($('#testReportArea').val()!=''){
                                    str+='<div class="content">' +
                                        '<p>试模报告</p>' +
                                        '<p class="testReport">'+$('#testReportArea').val()+'</p>' +
                                        '</div>';
                                }
                                str+='</div>' +
                                    '</li>';
                                $(_this).parents('li').before(str);

                                //初始化试模框
                                $(_this).parents('.contentBox').siblings('.title').html('<span class="testStartTxt">T'+$('.testT').length+'试模（未开始）</span>');
                                $(_this).parents('.contentBox').hide();
                                $(_this).parents('.contentBox').siblings('.testStart').show();
                                $(_this).parents('.contentBox').siblings('.testStart').html('开始T'+$('.testT').length+'试模');
                                if($('.testT').length>1){
                                    $('.testStorage').show();
                                }else{
                                    $('.testStorage').hide();
                                }
                            }else {
                                layer.open({
                                    content: data.code+' '+data.message
                                    ,btn: '确定'
                                });
                            }
                        },
                        error: function(e) {
                            layer.closeAll();
                            layer.open({
                                content: '无法请求服务器，请稍后再试！'
                                ,btn: '确定'
                            });
                        }
                    });
                }else{
                    $('.group').css('color','red');
                    layer.open({
                        content: '请选择问题负责组别'
                        ,btn: '确定'
                    });
                }
            },no: function(index){
                console.log(index)
            }
        });
    });
    //试模入库
    $('.main').on('click','.testStorage',function () {
        layer.open({
            content: '完成试模，模具入库'
            ,btn: ['确定', '取消']
            ,yes: function(index){
                layer.close(index);
                layer.open({type: 2,shadeClose: false,});
                var url='/test/mode/handle';
                var mdObj=md5Fun(appUserId,url,appToken);
                var parameterObj= {
                    "id":$('.modeInfo').attr('data-id'),
                    "type":3,
                    "partCode":partCode,
                };
                var parameter=Encrypt(JSON.stringify(parameterObj));
                console.log(parameter)
                console.log(Decrypt(parameter));
                $.ajax({
                    type: "POST",
                    timeout : 5000,
                    url: webUrlCon+url,
                    data:JSON.stringify(
                        {"parameter":parameter}
                    ),
                    beforeSend: function(request) {
                        request.setRequestHeader("Content-Type", "application/json");
                        request.setRequestHeader("sequence", mdObj.sequence);
                        request.setRequestHeader("nonceStr", mdObj.nonceStr);
                        request.setRequestHeader("userId", appUserId);
                        request.setRequestHeader("token",appToken);
                        //xmlhttp.setRequestHeader("infName", url);
                        //xmlhttp.setRequestHeader("osVersion", '');
                        request.setRequestHeader("versionType", "1");
                        request.setRequestHeader("osPlatform", mdObj.osPlatform);
                        request.setRequestHeader("appVersion", mdObj.appVersion);
                        request.setRequestHeader("sign", mdObj.sign);
                    },
                    success: function (data) {
                        layer.closeAll();
                        console.log(data);
                        if(data.code==100) {
                            var content=Decrypt(data.content);
                            content=JSON.parse(content);
                            console.log(content);
                            layer.open({
                                content: '模具入库成功，跳转到历史试模页面'
                                ,btn: '确定'
                                ,shadeClose:false
                                , yes: function(index){
                                    layer.close(index)
                                    if (u.indexOf('iPhone') > -1) {   //苹果手机
                                        location.href='testHistory.html';
                                    }else {
                                        jsObj.openHyperLinkReference('testHistory.html');
                                    }
                                }
                            });
                        }else {
                            layer.open({
                                content: data.code+' '+data.message
                                ,btn: '确定'
                            });
                        }
                    },
                    error: function(e) {
                        layer.closeAll();
                        /*layer.open({
                            content: '无法请求服务器，请稍后再试！'
                            ,btn: '确定'
                        });*/
                    }
                });

            },no: function(index){
                console.log(index)
            }
        });
    });
    //删除试模
    $('.main').on('click','.testDel',function () {
        var _this=this;
        layer.open({
            content: '删除试模?'
            ,btn: ['确定', '取消']
            ,yes: function(index){
                layer.close(index);
                layer.open({type: 2,shadeClose: false,});
                var url='/test/mode/handle';
                var mdObj=md5Fun(appUserId,url,appToken);
                var parameterObj= {
                    "type":4,
                    "partCode":partCode,
                    "testModeDetailid":$('.testInfo').attr('test-mode-detailid')
                };
                var parameter=Encrypt(JSON.stringify(parameterObj));
                console.log(parameter)
                console.log(Decrypt(parameter));
                $.ajax({
                    type: "POST",
                    timeout : 5000,
                    url: webUrlCon+url,
                    data:JSON.stringify(
                        {"parameter":parameter}
                    ),
                    beforeSend: function(request) {
                        request.setRequestHeader("Content-Type", "application/json");
                        request.setRequestHeader("sequence", mdObj.sequence);
                        request.setRequestHeader("nonceStr", mdObj.nonceStr);
                        request.setRequestHeader("userId", appUserId);
                        request.setRequestHeader("token",appToken);
                        //xmlhttp.setRequestHeader("infName", url);
                        //xmlhttp.setRequestHeader("osVersion", '');
                        request.setRequestHeader("versionType", "1");
                        request.setRequestHeader("osPlatform", mdObj.osPlatform);
                        request.setRequestHeader("appVersion", mdObj.appVersion);
                        request.setRequestHeader("sign", mdObj.sign);
                    },
                    success: function (data) {
                        layer.closeAll();
                        console.log(data);
                        if(data.code==100) {
                            var content=Decrypt(data.content);
                            content=JSON.parse(content);
                            console.log(content);
                            $(_this).parents('.contentBox').siblings('.title').html('<span class="testStartTxt">T'+$('.testT').length+'试模（未开始）</span>');
                            $(_this).parents('.contentBox').hide();
                            $(_this).parents('.contentBox').siblings('.testStart').show();
                            $(_this).parents('.contentBox').siblings('.testStart').html('开始T'+$('.testT').length+'试模');
                        }else {
                            layer.open({
                                content: data.code+' '+data.message
                                ,btn: '确定'
                            });
                        }
                    },
                    error: function(e) {
                        layer.closeAll();
                        layer.open({
                            content: '无法请求服务器，请稍后再试！'
                            ,btn: '确定'
                        });
                    }
                });

            },no: function(index){
                console.log(index)
            }
        });
    });
    /* 上传图片=============================== */
    /*$('.main').on('change','.photoInput',function () {
        if($(this).val()!=''){
            $('.loading').css('z-index','5');
        }
        var _this = this;
        var file = _this.files[0];
        var base64='';
        var base64Data='';
        var key ='img/h5/test2017_'+new Date().getTime()+'.JPG';
        lrz(file, {
            width: 1548
        })
            .then(function(rst) {
                base64=rst.base64;
                base64Data = base64.replace(/^data:image\/\w+;base64,/, "");
                base64Data = base64Data.replace(/\s/g,"+");
                client.put(key, new Buffer(base64Data,'base64')).then(function (result) {
                    console.log(result);
                    var imgBase='<div class="img">' +
                        '<i class="fileDel  iconfont icon-shanchu1"></i>' +
                        '<img data-url="'+result.name+'" src="'+base64+'">' +
                        '</div>';
                    $('.testImagesFile').before(imgBase)
                    if($('#testImages .img').length>3){
                        $('.testImagesFile').hide();
                    }else{
                        $('.testImagesFile').show();
                    }
                }).catch(function (err) {
                    console.log(err);
                });
                return rst;
        }).always(function () {
            // 不管是成功失败，都会执行
            $('.loading').css('z-index','1');
        });
    });*/

    //删除图片
    $('.main').on('click','.fileDel',function () {
        var _this=this;
        layer.open({
            content: '是否删除图片'
            ,btn: ['确定', '取消']
            ,yes: function(index){
                layer.close(index);
                $(_this).parent('div').remove();
                if($('#testImages .img').length>3){
                    $('.testImagesFile').hide();
                }else{
                    $('.testImagesFile').show();
                }
            }
        });
    });
    //切换试模菜单
    $('body').on('click', '.TabNavUl li', function () {
        testListHtml(parseInt($(this).attr('data-id')));
    })

    tabNavInit()
    tabNavRefresh()
})


/*
* tabNav 菜单切换
* */

function tabNavInit() {
    $('body').on('click', '.TabNavUl li', function () {
        $(this).parent('.TabNavUl').children('li').removeClass('active');
        $(this).addClass('active');
        $(this).siblings('.lanPos').css({
            'left': $(this).get(0).offsetLeft,
            'width': $(this).children('span').get(0).clientWidth
        });
        $(this).parent('.TabNavUl').animate({scrollLeft: $(this).get(0).offsetLeft - ($('.TabNavUl').width() / 2) + ($(this).children('span').get(0).clientWidth / 2)}, 300);
    });
}
function tabNavRefresh() {
    $('.TabNavUl').each(function () {
        if ($(this).find('.lanPos').length == 0) {
            $(this).append('<div class="lanPos"></div>');
        }
        $(this).find('.lanPos').css({
            'left': $(this).find('.active').get(0).offsetLeft,
            'width': $(this).find('.active').children('span').get(0).clientWidth
        });
        $(this).animate({scrollLeft: $(this).find('.active').get(0).offsetLeft - ($('.TabNavUl').width() / 2) + ($(this).find('.active').children('span').get(0).clientWidth / 2)}, 1);
    })
}
